package com.smart.community.commons.config;

import com.smart.community.commons.exception.GlobalExceptionHandler;
import com.smart.community.commons.utils.RedisUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 通用组件自动配置类
 * @author Wu.Liang
 * @since 2024-12-19
 * @version 1.0.0
 */
@Configuration
@ComponentScan(basePackages = "com.smart.community.commons")
public class CommonsAutoConfiguration implements WebMvcConfigurer {
    
    /**
     * 全局异常处理器
     * 
     * @return 全局异常处理器
     */
    @Bean
    @ConditionalOnMissingBean
    public GlobalExceptionHandler globalExceptionHandler() {
        return new GlobalExceptionHandler();
    }
    
    /**
     * 用户上下文拦截器
     * 
     * @return 用户上下文拦截器
     */
    //@Bean
    //@ConditionalOnMissingBean
    //public UserContextInterceptor userContextInterceptor() {
    //    return new UserContextInterceptor();
    //}
    
    /**
     * Redis工具类
     * 
     * @return Redis工具类
     */
    @Bean
    @ConditionalOnMissingBean
    public RedisUtil redisUtil() {
        return new RedisUtil();
    }
    
    /**
     * 添加拦截器
     * 
     * @param registry 拦截器注册表
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    }
}
